var DESIGN_MODE = !true;
var currentSegmentId, currentSegmentData, curPage, curPageData;
var isCorrectAns = false;
var nextSegment = "";
var curKeySeq = "";
var validateKeySeq = "";
var seqLen;
var canTakeKeyDown = true;
var incorrectMsg = false;
var isShowDropdown = false;
var isTextField = false;
var hideGlobalKey = false;
var isShowFileSubMenuKeys = false;
var isDropdownSeqLen;
var incorrectAttempts = 2;
var deadElementsInClick, deadElementsInKeys;
var isFileMenu = !true;

$(document).keydown(function(e) { //Should be the FIRST keydown handler

});

$(document).keydown(function(e) {
    if (canTakeKeyDown == false && ((e.which == 121 && !e.shiftKey) || e.which == 18))
        return false;
    
    canTakeKeyDown = false;
    document.title = e.which;
    var curChar = String.fromCharCode(e.which);
    if (e.which == 27) {
        curKeySeq = "";
    } else if (e.which == 16 || e.which == 17) {
        return;
    } else if ((e.which == 73 && e.altKey && e.ctrlKey) || 
    (e.which == 80 && e.ctrlKey) || 
    (e.which == 113 && e.ctrlKey) || 
    (e.which == 123 && e.ctrlKey && e.shiftKey)) {
        fileMenuPreviousTab = curPage;
        incorrectMsg = true;
        curKeySeq = "\x12FP";
        isShowFileMenu = true;
        $("#questioncontainer").css({"z-index": "0"});
    } else {
        if (curKeySeq == "" && e.which == 121 && !e.shiftKey) {
            curChar = String.fromCharCode(18);
		}
        curKeySeq += curChar;
    }

    //DISABLING BROWSER KEYS - CHROME
    if (e.which == 72 && e.ctrlKey) {
        log("old", "testttttttttttst");
        incorrectMsg = true;
        return false;
    }
    
	 return handleKey(e);
});

$(document).keyup(function(e) {
    //log("info", "framework.js -> keyup::currentSegmentId: " + currentSegmentId);
    //log("info", "framework.js -> keyup::incorrectMsg: " + incorrectMsg);
    canTakeKeyDown = true;
    
    if (e.which == 16 || e.which == 17 || e.which == 18) {
        return;
    }
    
    if (incorrectMsg == false && currentSegmentId.split('_')[1] != "RESULT") {
        if (isTextField == false){
            doKeyWrongAction();
		}
    }
	
	incorrectMsg = false;
	
    log("keyup", "framework.js -> keyup::start");
    log("keyup", "currentSegmentId: " + currentSegmentId);	
    log("keyup", "incorrectMsg: " + incorrectMsg);
    log("keyup", "curKeySeq: " + curKeySeq);
    log("keyup", "seqLen: " + seqLen);
	log("keyup", "isShowRightClickMenu: " + isShowRightClickMenu);
	log("keyup", "isShowDropdown: " + isShowDropdown);     
    log("keyup", "framework.js -> keyup::end");
});

function handleKey(e) {
    log("info", "currentSegmentId:" + currentSegmentId);
    var allowedKeys;
    var retVal = true;
    
    seqLen = curKeySeq.length;
    var matchCount = 0;
    var actionDone = false;
    $(".keypanel").remove();
    document.title = "";
    keysDisplayed = [];
    
    if (seqLen == 1 && curKeySeq == '\x12' && !isShowDropdown) {
        retVal = false;
        $(document).focus();
        incorrectMsg = true;
        log("info", "isShowFileMenu=" + isShowFileMenu)
        if (isShowFileMenu == "true" || isShowFileMenu == true) {
            for (var i in fileKeyLevelAction) {
                matchCount++;
                displayKey(i, fileKeyLevelAction[i], false);
            }
            curKeySeq = "\x12F";
            seqLen = curKeySeq.length;
        } else {
            for (var i in keyLevel1Action) {
                matchCount++;
                displayKey(i, keyLevel1Action[i], false);
            }
        }
        log("info", isShowFileMenu + "ALT...Pressed..." + incorrectMsg)
    } else {
        //this code is used to change the navigation image according to the selected tab
        if (seqLen == 2 && curKeySeq.indexOf('\x12') == 0) {
            if (curKeySeq.substring(1, 2) == "F") {
                fileMenuPreviousTab = curPage;
                isShowFileMenu = true;
                $("#questioncontainer").css({"z-index": "0"});
            
            }
            if (seqLen == 2 && curKeySeq.indexOf('\x12') == 0 && (isShowFileMenu == "true" || isShowFileMenu == true)) {
                isShowFileMenu = true;
                changeFileMenuTab(curKeySeq.substring(1, 2));
                log("info", "hhhhhhh" + seqLen + "---" + keyData[curPage][0][4].substring(seqLen + 1));
                for (var i = 0; i < keyData[curPage].length; i++) {
                    if (e.which != 18 && e.which != 70)
                        displayKey(keyData[curPage][i][4].substring(seqLen + 1), keyData[curPage][i], (keyData[curPage][i][5] == 'Y'));
                }
            //incorrectMsg=true;
            }
            if (keyLevel1Action[curKeySeq.substring(1, 2)] && curPage <= 8) {
                incorrectMsg = true;
                log("info", "hellow--------" + isShowFileMenu)
                actionLoadPage(keyLevel1Action[curKeySeq.substring(1, 2)][4].substring(1));
            } else {
                incorrectMsg = false;
                curKeySeq = "";
                seqLen = 0;
            }
        }
		
        //this code is used to change the navigation image according to the selected tab
        
        else if (seqLen == 3 && curKeySeq.indexOf('\x12') == 0 && curKeySeq.indexOf('F') == 1) {
            isShowFileSubMenuKeys = true;
            changeFileMenuTab(curKeySeq.substring(2, 3));            
        }
        
        if (isFileMenu == true) {
            questionFileMenuKey(e);
        }
        
        for (var i = 0; i < keyData[curPage].length; i++) {
            
            if (keyData[curPage][i][4].indexOf(curKeySeq) == 0) {
                retVal = false;
                if (seqLen == 1) {
                    matchCount++;
                
                } else if (keyData[curPage][i][4] == curKeySeq) {
                    isDropdownSeqLen = seqLen;
                    doKeyAction(e, curKeySeq);
                    curKeySeq = "";
                    break;
                } else if (seqLen > 1) {
                    if (seqLen == 2 && !actionDone) {
                        if (curKeySeq.substring(1, 2) == "F") {
                            actionDone = false;
                            isShowFileMenu = true;
                        } else {
                            actionDone = true;
                        }
                        
                        $(keyLevel1Action[curKeySeq.substring(1, 2)][4]).each(function(idx, item) {
                            doAction(item, false);
                        });
                    } else if (seqLen == 3 && !actionDone) {
                        actionDone = true;
                        $(keyLevel1Action[curKeySeq.substring(1, 2)][4]).each(function(idx, item) {
                            doAction(item, false);
                        });
                    }
                    matchCount++;
                    
                    if (isShowFileMenu) {
                        displayKey(keyData[curPage][i][4].substring(seqLen), keyData[curPage][i], (keyData[curPage][i][5] == 'Y'));
                    } else {
                        if (!hideGlobalKey)
                            displayKey(keyData[curPage][i][4].substring(seqLen > 2 ? 2 : seqLen), keyData[curPage][i], (keyData[curPage][i][5] == 'Y'));
                    }
                }
            }
        }
        
        if (isShowRightClickMenu && !isShowSubMenu) {
            doRightClickKeyAction(e, e.which)
        } else if (isShowSubMenu) {
            doRightClickSubMenuKeyAction(e.which)
        } else if (isShowFileMenu) {
            if (event.which == 37 || event.which == 38 || event.which == 39 || event.which == 40) {
                doFileMenuKeyHandler(event.which)
            } else {
                keyHandler(event.which, event.ctrlKey, event.shiftKey, event.altKey);
            }
        } else {
            keyHandler(e.which, e.ctrlKey, e.shiftKey, e.altKey);
        }
        if (isDropdownSeqLen == 3 && (isShowDropdown == "true" || isShowDropdown == true)) {
            for (var i in dropDownKeys) {
                //	matchCount++;
                displayKey(i, dropDownKeys[i], false);
            }
        }
    }
    if (matchCount == 0) {
        if ('\x12\x79'.indexOf(curKeySeq.substring(curKeySeq.length - 1)) > -1) {
            retVal = false;
            if (e.which == 18) {
                incorrectMsg = true;
            }
        }
        curKeySeq = "";
    }
    
    if ((isShowDropdown == "true" || isShowDropdown == true) && (isShowRightClickMenu == false || isShowRightClickMenu == "false")) {
        incorrectMsg = true;
        $("#glasscontainer").html('');
        log("gopal111", "in key up frame work...")
        doDropdownkeyHandler(e.which);
    }
    
    globalDeadKeys(e.which, e.ctrlKey, e.shiftKey, e.altKey);
	
    if (e.shiftKey && e.which == 121) {
        doRightClickUsingKeys(e, $("#rightclickmenucontainer"));
        incorrectMsg = true;
    }
    
    return retVal;
}

var keysDisplayed = [];

function doKeyWrongAction() {
    showIncorrect();
}

function doKeyAction(e, keySeq) {
    keysDisplayed = [];
    $(".keypanel").remove();
    doAction(e, "a_" + keySeq, false);
}

function displayKey(text, pos, isDehighlight) {
    if (keysDisplayed.indexOf(text) > -1)
        return;
    
    keysDisplayed[keysDisplayed.length] = text;
    
    var gCtrl = $("#glasscontainer")
    var newItem = $("<div class='keypanel' style='background-color:#404040;text-align:center;color:white;font-family:verdana;font-size:12px;position:absolute;left:" + pos[0] + "px;top:" + pos[1] + "px;width:20px;height:16px;cursor:default;'>" + text + "</div>");
    if (isDehighlight)
        newItem.css("opacity", "0.5");
    if (isShowDropdown) {
        $("#questioncontainer").append(newItem)
    } else {
        gCtrl.append(newItem);
    }
}

function keyHandler(curKey, ctrlKey, shiftKey, altKey) {
    var correctKey, deadKey;    
    var exitPath;
    var isValidation = !true;
    var isValidated = !true;
    var correctElementFound = !true;
    
    correctKey = currentSegmentData.keys.keyUp.correct
    deadKey = currentSegmentData.keys.keyUp.dead
    for (var j = 0; j < correctKey.length; j++) {
        if (correctKey[j].ctrl == String(ctrlKey) && 
        correctKey[j].shift == String(shiftKey) && 
        correctKey[j].alt == String(altKey) && 
        correctKey[j].seqLen == seqLen && 
        correctKey[j].rightClick == "false" && 
        correctKey[j].code == curKey) {
            
            isShowDropdown = correctKey[j].dropDown;
            
            for (var k = 0; k < currentSegmentData.exits.length; k++) {
                if (correctKey[j].exit == currentSegmentData.exits[k].id) {
                    if (currentSegmentData.exits[k].validation != undefined && 
                    currentSegmentData.exits[k].validation.length > 0) {
                        isValidation = true;
                    }
                    exitPath = currentSegmentData.exits[k].nextPath;
                    break;
                }
            }
            
            if (isValidation == true) {
                //Gopal TODO: need to validate the exit before move to next segment
                isValidated = true;
            } else {
                isValidated = true;
            }
            
            if (isValidated == true) {                
                incorrectMsg = true;                
				nextSegment = exitPath;
				isCorrectAns = true;
            }            
            break;
        }
    }
    
    if (isCorrectAns == false) {
        for (var d = 0; d < deadKey.length; d++) {
            if (deadKey[d].ctrl == String(ctrlKey) && 
            deadKey[d].shift == String(shiftKey) && 
            deadKey[d].alt == String(altKey) && 
            deadKey[d].seqLen == seqLen && 
            deadKey[d].code == curKey) {
                incorrectMsg = true;
                event.preventDefault();
            }
        }
    }
	
	if(isCorrectAns == true) {
		loadSegment(nextSegment);		
	}
}

function doClickAction(event, ctrl) {
    $(".keypanel").remove();    
    doAllAction(event, ctrl, 4);
}

function doOverAction(event, ctrl) {
    //log("old", "ctttl="+ctrl.id+"---"+isShowRightClickMenu)
    doAllAction(event, ctrl, 5);
}

function doOutAction(event, ctrl) {
    doAllAction(event, ctrl, 5, true);
}

function doRightClickAction(event, ctrl) {
    //doAllAction(event, ctrl, 6);
    actionOffice(event, ctrl);
}

function doAllAction(event, ctrl, idx, isActionRevert) {
    //log("old", isShowRightClickMenu+"actionList in fjs="+isShowSubMenu)
    var actionList = curPageData.marks[ctrl.id][idx];
    
    for (var i = 0; i < actionList.length; i++) {
        doAction(event, actionList[i], isActionRevert);
    }
}

function doAction(event, dataId, isActionRevert) {
    hideFileMenuTab(event, dataId);
    
    var actionType = dataId.substring(0, 1);
    
    if (actionType == 'p') {
        actionLoadPage(dataId.substring(1) - 0);
    }
    if (actionType == 'a') {
        actionOffice(event, dataId);
    }
    if ('hbBi'.indexOf(actionType) >= 0) {
        if (isActionRevert) {
            $("#" + dataId).hide();
        } else {
            $("#" + dataId).show();
        }
    }
}

function actionOffice(event, actionId) {
    log("old", "ACTION: " + actionId + "------" + event + "---" + currentSegmentId);
    log("info", event.which + "-hello---" + event.type + "----" + event.target.id)
    
    var exitPath, correctElement, deadElement;  
    
    incorrectMsg = true;
    
	if(event.target.id == "m_Bold") {
		if($("#editor1").css("font-weight") == "bold")
			$("#editor1").css("font-weight","normal");
		else 
			$("#editor1").css("font-weight","bold");
	}
	
	if(event.target.id == "m_Italic") {
		if($("#editor1").css("font-style") == "italic")
			$("#editor1").css("font-style","normal");
		else
			$("#editor1").css("font-style","italic");
	}
	
	if(event.target.id == "m_Underline") {
		if($("#editor1").css("text-decoration") == "underline")
			$("#editor1").css("text-decoration","none");
		else
			$("#editor1").css("text-decoration","underline");
	}
	
	if(event.target.id == "m_AlignCenter") {
		$("#editor1").css("text-align","center");
	}
	
	if(event.target.id == "m_AlignLeft") {
		$("#editor1").css("text-align","left");
	}
	
	if(event.target.id == "m_AlignRight") {
		$("#editor1").css("text-align","right");
	}
	
	if(event.target.id == "m_AlignJustify") {
		$("#editor1").css("text-align","justify");
	}
	return;
	
    if (event.type != "contextmenu" && event.type != "dblclick") {
        //correctElement = currentSegmentData.click.correct;
        //deadElement = currentSegmentData.click.dead;
    
    } else if (event.type != "contextmenu" && event.type == "dblclick") {
        //correctElement = currentSegmentData.doubleClick.correct;
        //deadElement = currentSegmentData.doubleClick.dead;
    
    } else {
        //correctElement = currentSegmentData.rightClick.correct;
        //deadElement = currentSegmentData.rightClick.dead;
        
        incorrectMsg = true;
        
        var itemMactched = false;
        for (var j = 0; j < correctElement.length; j++) {
            if (correctElement[j] == event.target.id.substring(2)) {
                doRightClickHandler(event, $("#rightclickmenucontainer"));
                itemMactched = true;
                break;
            }
        }
    }
    var strId = "";
    if (event.type == "keydown" || event.type == "keyup") {
        strId = actionId;
    } else {
        strId = event.target.id.substring(2);
    }  
    
    var isValidation = !true;
    var isValidated = !true;
    var exitPath;
    for (var j = 0; j < correctElement.length; j++) {
        
        if (correctElement[j].name == strId) {
            for (var k = 0; k < currentSegmentData.exits.length; k++) {
                if (correctElement[j].exit == currentSegmentData.exits[k].id) {
                    if (currentSegmentData.exits[k].validation != undefined && 
                    currentSegmentData.exits[k].validation.length > 0) {
                        isValidation = true;
                    }
                    exitPath = currentSegmentData.exits[k].nextPath;
                    break;
                }
            }
            
            if (isValidation == true) {
                //Gopal TODO: need to validate the exit before move to next segment
                isValidated = true;
            } else {
                isValidated = true;
            }
            
            if (isValidated == true) {                
                incorrectMsg = true;                
				nextSegment = exitPath;
				isCorrectAns = true;
            }            
            break;
        }
    }

    // if correct element not found than only will check in dead elements
    if (isCorrectAns == false) {
        for (var d = 0; d < deadElement.length; d++) {
            if (deadElement[d] == event.target.id.substring(2)) {
                incorrectMsg = true;
                break;
            }
        }
    }
	
	if(isCorrectAns == true) {
		loadSegment(nextSegment);
	}
}

function loadSegment(segmentId) {
	isCorrectAns = false;
	var segmentData = getSegmentData(segmentId);
	currentSegmentData = segmentData;
    currentSegmentId = segmentData.id;
	   
    if (!isShowFileMenu) {        
        if (segmentData.size != "long") {
            $("#question")[0].src = segmentData.path;
			$("#question").show();
			$("#questionImgLong").hide();
        } else {
            $("#questioncontainer").html('');
            $("#questionImgLong")[0].src = segmentData.path;
			$("#question").hide();
			$("#questionImgLong").show();
        }
        $("#questioncontainer").css({"z-index": "120"})
        if (currentSegmentId.split('_')[1] == "RESULT") {
            endSimulation("1");
        }
    } else if (isShowFileMenu == true) {
        
        $("#questioncontainer").html('');
        $("#questioncontainer").css({"z-index": "1"})
    } else {
        
        $("#questioncontainer").html('');
        $("#questioncontainer").css({"z-index": "50"})
    }
    
    if (isShowRightClickMenu) {
        $("#rightclickmenu").hide();
        $("#rightclickmenucontainer").html('');
        isShowRightClickMenu = false;
    }
 
	resetSegmentVariables();
    loadQuestions($("#questioncontainer"), currentSegmentId);    
}

function showIncorrect() {    
    if (!incorrectMsg) {
        // reset key sequence, sequence length and remove the alt keys.
        $(".keypanel").remove();
        curKeySeq = "";
        seqLen = 0;
        
        $("#incorrect").css("display", "block");
        $("#incorrect").fadeIn(1000, function() {
            timeout = setTimeout('hideIncorrect()', 1000);
        });
    } else {
        log("info", "incorrectMsg in showinc=in else..=" + incorrectMsg);
        incorrectMsg = false;
    }
    isTextField = false;
}

function hideIncorrect() {
    $("#incorrect").fadeOut(1000, function() {
        $("#incorrect").css("display", "none");
        clearTimeout(timeout);
        incorrectAttempts--;
        checkScore();
    });
}

function actionLoadPage(pageIdx) {
    
    if (pageIdx < pageData.length) {
        curPage = pageIdx;
        curPageData = $.extend({}, pageData[curPage]);
        
        if (curPage >= 8 && curPage <= 20) {
            $("#question").hide();
            isShowFileMenu = true;
        } else {
            $("#question").show();
            isShowFileMenu = false;
        }
        
        $("#headercontainer")[0].src = curPageData.headerimg;
        loadPageData();
        $("#incorrect")[0].src = '../images/incorrectMessage.png';
        log("info", "actionLoadPage-" + isShowFileMenu);
    }

}

function loadPageData() {
    var i, actionType, curItem, newItem, gCtrl = $("#glasscontainer"), hCtrl = $("#headercontainer");
    
    gCtrl.html("");
	
    setTimeout(function() {
        gCtrl.css({ left: hCtrl.position().left,
					top: hCtrl.position().top,
					width: hCtrl.width(),
					height: hCtrl.height()});
    }, 100);
    
    for (i in curPageData.htmls) {
        curItem = curPageData.htmls[i];
        newItem = $(curItem[4]);
        newItem.css({
            position: "absolute",
            border: "0px",
            //"z-index": 9,
            left: curItem[0] + "px",
            top: curItem[1] + "px",
            width: (curItem[2] - curItem[0]) + "px",
            height: (curItem[3] - curItem[1]) + "px"
        });
        gCtrl.append(newItem);
    }
    
    for (i in curPageData.marks) {
        curItem = curPageData.marks[i];
        
        newItem = $("<div></div>");
        newItem.attr("id", i);
        if (!DESIGN_MODE) {
            newItem.attr("onclick", "doClickAction(event, this);");
            newItem.attr("onmouseover", "doOverAction(event, this)");
            newItem.attr("onmouseout", "doOutAction(event, this)");
            newItem.attr("oncontextmenu", "doRightClickAction(event, this)");
        } else {
            newItem.attr("title", i);
        }
        newItem.css({
            border: (DESIGN_MODE ? "1px solid blue" : "0px"),
            position: "absolute",
            "z-index": 99,
            left: curItem[0] + "px",
            top: curItem[1] + "px",
            width: (curItem[2] - curItem[0]) + "px",
            height: (curItem[3] - curItem[1]) + "px"
        });
        
        applyMouseCursor(newItem, i);
        gCtrl.append(newItem);
    }
    
    for (i in curPageData.action) {
        actionType = i.substring(0, 1);
        
        if ('i'.indexOf(actionType) >= 0) {
            curItem = curPageData.action[i];
            newItem = $('<img src="' + curItem[4] + '"></img>');
            newItem.attr("id", i);
            newItem.css({
                display: "none",
                position: "absolute",
                left: curItem[0] + "px",
                top: curItem[1] + "px"
            });
            gCtrl.append(newItem);
        } else if ('hbB'.indexOf(actionType) >= 0) {
            curItem = curPageData.action[i];
            newItem = $("<div></div>");
            newItem.attr("id", i);
            newItem.css({
                display: "none",
                "background-color": (actionType == 'h' ? "LightSteelBlue" : ""),
                border: (actionType == 'b' ? "1px solid lightblue" : (actionType == 'B' ? "4px solid LightSteelBlue" : "0px")),
                'box-sizing': 'border-box',
                opacity: 0.5,
                position: "absolute",
                left: curItem[0] + "px",
                top: curItem[1] + "px",
                width: (curItem[2] - curItem[0]) + "px",
                height: (curItem[3] - curItem[1]) + "px"
            });
            gCtrl.append(newItem);
        }
    }
}



function globalDeadEvents(event) {
    deadElementsInClick = globalJSON.hotspots.click.dead;
    for (var i = 0; i < deadElementsInClick.length; i++) {
        if (deadElementsInClick[i].name == event.target.id.substring(2)) {
            incorrectMsg = true;
            break;
        } /*else{
			//incorrectMsg=false;
		}*/
    }
}

function applyMouseCursor(item, id) {
    if (id == "m_FileNewBusiness" || 
    id == "m_FileNewPersonel" || 
    id == "m_FileNewIndustry" || 
    id == "m_FileNewPrint" || 
    id == "m_FileNewDesignSets" || 
    id == "m_FileNewEvent" || 
    id == "m_FileNewEducation") {
        item.css({cursor: "pointer"});
    }
}

function globalDeadKeys(curKey, ctrlKey, shiftKey, altKey) {
    deadElementsInKeys = globalJSON.keys.keyUp.dead;    
    for (var i = 0; i < deadElementsInKeys.length; i++) {
        if (deadElementsInKeys[i].code == curKey && deadElementsInKeys[i].ctrl == String(ctrlKey) && deadElementsInKeys[i].shift == String(shiftKey) && deadElementsInKeys[i].alt == String(altKey)) {
            incorrectMsg = true;
            break;
        }
    }
}

function actionLoadFileSubMenu(curKeySeq) {
    log("old", "actionLoadFileSubMenu...")
    curPageData = $.extend({}, pageData[curPage]);
    keyDataTemp = keyData[curPage];
    for (var i = 0; i < keyDataTemp.length; i++) {
        if (curKeySeq == keyDataTemp[i][4]) {
            selectedTabData = keyDataTemp[i];
            break;
        }
    }

//$("#filemenu")[0].src = selectedTabData[6]["image"];
}

function endSimulation(score) {
    var qaMode = globalJSON.qaMode.enabled;
    if (qaMode == "false") {
        setTimeout(function() {
        //parent.handleHtmlResults(score)
        }, 1000);
    
    }
}

function checkScore() {
    var qaMode = globalJSON.qaMode.enabled;
    
    if (qaMode == "false") {
        
        if (incorrectAttempts <= 0) {
            
            endSimulation("0");
        }
    }
}

function initApp(ctrl, curTab) {
    var strHtmlText = "";
    curPage = curTab;
    strHtmlText += '<img id="headercontainer" class="headercontainer"></img>';
    strHtmlText += '<img id="incorrect" class="incorrect"></img>';
    strHtmlText += '<div id="glasscontainer" class="glasscontainer"></div>';
	strHtmlText += '<div style="left:62px; top:142px; height:430px; width:810px; z-index:9998; position:absolute;">';
	strHtmlText += '<textarea name="editor1" id="editor1" style="font-size:18px; height:430px; width:810px;">Welcome 2 CEB</textarea>';
	strHtmlText += '</div>';
    strHtmlText += '<img id="question" class="question"></img>';
    strHtmlText += '<img id="questionImgLong" class="questionImgLong"></img>';
	
	
    strHtmlText += '<div id="questioncontainer" class="questioncontainer"></div>';
    strHtmlText += '<img id="rightclickmenu" class="rightclickmenu"></img>';
    strHtmlText += '<div id="rightclickmenucontainer" class="rightclickmenucontainer"></div>';
    strHtmlText += '<div id="submenucontainer" class="submenucontainer"></div>';
    strHtmlText += '<img id="submenu" class="submenu"></img>';
	
	
	
    ctrl.html(strHtmlText);
    if (DESIGN_MODE) {
        $("#glasscontainer, #questioncontainer").click(function(e) {
            alert(e.offsetX + ", " + e.offsetY);
        });
    }
    $("#glasscontainer,#questioncontainer,#rightclickmenucontainer,#submenucontainer").click(function(e) {
        $(".keypanel").remove();
        globalDeadEvents(e);
        showIncorrect();        
    });
    $(document).bind("contextmenu", function(e) {
        incorrectMsg = false;
        $(".keypanel").remove();
        return false;
    });
    
    actionLoadPage(curPage);
    
    loadSegment(currentSegmentId);
	
	$("#editor1").val(questionData[0].content);
	
	//parent.handleSimOkClick(1);
}

function log(type, msg) {
    if (type == "keyup")
        console.log(msg);
}

function getSegmentData(segmentId) {
    for (var i = 0; i < questionData.length; i++) {
        if (questionData[i].id == segmentId) {
            return questionData[i];
        }
    }
    
    return null;
}

function resetSegmentVariables() {
	
}